//
//  GYSaleProductDetailCell.m
//  GYDemo
//
//  Created by Mrzhang on 2018/4/8.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYSaleProductDetailCell.h"
#import "Head.h"
#import <SDCollectionViewCell.h>
@interface GYSaleProductDetailCell ()<SDCycleScrollViewDelegate>
@property(nonatomic,strong)UILabel* titleLab;
@property(nonatomic,strong)UILabel* priceLab;

@property(nonatomic,strong)UILabel* countLab;
@property(nonatomic,strong)UILabel* DealCountLab;
@property(nonatomic,strong)SDCycleScrollView* bannerScroll;
@property(nonatomic,strong)UIImageView* lineIV;

@end;

@implementation GYSaleProductDetailCell

#pragma mark setter getter

-(SDCycleScrollView *)bannerScroll
{
    if (!_bannerScroll) {
        _bannerScroll=[SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH) delegate:self placeholderImage:DefaultImage];
        _bannerScroll.backgroundColor=Main_Color_BGLightGray;
        _bannerScroll.currentPageDotColor=Main_Color_Red;
        _bannerScroll.pageDotColor=RGBACOLOR(216, 216, 216, 0.5);
        _bannerScroll.bannerImageViewContentMode=UIViewContentModeScaleAspectFill;
    }
    return _bannerScroll;
}
-(UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab=[[UILabel alloc] init];
        _titleLab.textColor=Main_Color_Black;
        _titleLab.font=SYSTEMFONT(15);
        _titleLab.numberOfLines=3;
        
    }
    return _titleLab;
}

-(UILabel *)priceLab
{
    if (!_priceLab) {
        _priceLab=[[UILabel alloc] init];
        _priceLab.textColor=Main_Color_Red;
        _priceLab.font=SYSTEMFONT(17);
    }
    return _priceLab;
}
-(UIImageView *)lineIV
{
    if (!_lineIV) {
        _lineIV=[[UIImageView alloc] init];
        _lineIV.x=WFCGFloatX(299);
        _lineIV.y=ScreenWidth+WFCGFloatY(105);
        _lineIV.width=1;
        _lineIV.height=19;
        _lineIV.backgroundColor=HEXCOLOR(@"#979797");
    }
    return _lineIV;
}

-(UILabel *)countLab
{
    if (!_countLab) {
        _countLab=[[UILabel alloc] init];
        _countLab.textColor=HEXCOLOR(@"#999999");
        _countLab.font=SYSTEMFONT(13);
    }
    return _countLab;
}


-(UILabel *)DealCountLab
{
    if (!_DealCountLab) {
        _DealCountLab=[[UILabel alloc] init];
        _DealCountLab.textColor=HEXCOLOR(@"#999999");
        _DealCountLab.font=SYSTEMFONT(13);
        _DealCountLab.textAlignment=NSTextAlignmentCenter;
    }
    return _DealCountLab;
}
-(UIButton *)shareBtn{
    if (!_shareBtn) {
        _shareBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _shareBtn.x=WFCGFloatX(300);
        _shareBtn.y=ScreenWidth+WFCGFloatY(97);
        _shareBtn.width=WFCGFloatX(75);
        _shareBtn.height=WFCGFloatY(43);
        
        
        UIImageView* locationIV=[[UIImageView alloc] init];
        locationIV.image=[UIImage imageNamed:@"saledetail_share"];
        locationIV.y=0;
        locationIV.width=locationIV.image.size.width;
        locationIV.height=locationIV.image.size.height;
        locationIV.x=(WFCGFloatX(75)-locationIV.width)/2;
        [_shareBtn addSubview:locationIV];
        
        UILabel* HLable=[[UILabel alloc] init];
        HLable.x=0;
        HLable.y=locationIV.height+3;
        HLable.width=_shareBtn.width;
        HLable.height=WFCGFloatY(17);
        HLable.font=SYSTEMFONT(12);
        HLable.textColor=HEXCOLOR(@"#666666");
        HLable.text=@"分享";
        HLable.textAlignment=NSTextAlignmentCenter;
        [_shareBtn addSubview:HLable];
        
        
    }
    return _shareBtn;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.bannerScroll];
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.priceLab];
        [self.contentView addSubview:self.countLab];
        [self.contentView addSubview:self.DealCountLab];
//        [self.contentView addSubview:self.lineIV];
//        [self.contentView addSubview:self.shareBtn];

    }
    return self;
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{

    NSMutableArray* arr=[NSMutableArray new];

    [arr addObject:_inforModel.imgpath];
    PYPhotoBrowseView *photoBroseView = [[PYPhotoBrowseView alloc] init];
    
    // 2.1 设置图片源(UIImageView)数组
    photoBroseView.imagesURL = arr;
  //  photoBroseView.sourceImgageViews = sourceImageArr;
    photoBroseView.currentIndex=index;
    photoBroseView.frameToWindow=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
    photoBroseView.frameFormWindow=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
    // 3.显示(浏览)
    [photoBroseView show];

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    if (_inforModel)
    {
        if (_inforModel.imgpath)
        {
            _bannerScroll.imageURLStringsGroup=@[_inforModel.imgpath];
        }
        
        NSString* nameStr=_inforModel.name;
//        if (nameStr.length>8) {
//            nameStr=[nameStr substringToIndex:8];
//        }
        _titleLab.text=nameStr;

        CGSize titleSize = [WFFunctions WFStrGetSize:_titleLab.text width:WFCGFloatX(350) font:SYSTEMFONT(15)];

        _titleLab.x=WFCGFloatX(11);
        _titleLab.y=ScreenWidth+WFCGFloatY(11);
        _titleLab.width=ScreenWidth-WFCGFloatX(22);
        _titleLab.height=WFCGFloatY(titleSize.height);
        
        _priceLab.frame=WFCGRectMake(12.5, 40+250+8, 200, 17);
        
        _priceLab.x=WFCGFloatX(11);
        _priceLab.y=ScreenWidth+WFCGFloatY(82);
        _priceLab.width=ScreenWidth-WFCGFloatX(22);
        _priceLab.height=WFCGFloatY(25);
        
        NSString* unitStr=@"/件";
        _priceLab.text=[NSString stringWithFormat:@"%@%@",_inforModel.price,unitStr];
        
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_priceLab.text attributes:@{
                                                                                                                               NSFontAttributeName: SYSTEMFONT(21),
                                                                                                                               NSForegroundColorAttributeName:Main_Color_Red
                                                                                                                               }];
        [attributedString addAttribute:NSFontAttributeName value:SYSTEMFONT(12) range:NSMakeRange(_priceLab.text.length-unitStr.length, unitStr.length)];

        _priceLab.attributedText=attributedString;

        NSString* unitstr=@"";
        
        _countLab.x=WFCGFloatX(11);
        _countLab.y=ScreenWidth+WFCGFloatY(113);
        _countLab.width=WFCGFloatX(120);
        _countLab.height=WFCGFloatY(19);
        _countLab.text=[NSString stringWithFormat:@"数量:99%@",unitstr];
        
        _DealCountLab.x=WFCGFloatX(140);
        _DealCountLab.y=ScreenWidth+WFCGFloatY(113);
        _DealCountLab.width=WFCGFloatX(150);
        _DealCountLab.height=WFCGFloatY(19);
        
        _DealCountLab.text=[NSString stringWithFormat:@"起订数量:%@%@",@"1",unitstr];
        _DealCountLab.textAlignment=NSTextAlignmentLeft;
 
    }
}
@end
